#include <stdio.h>
#include "bit.h"

#define BIT3	(0x1 << 3)

static int a;

void set_bit3(void)
{
	a |= BIT3;
}

void clear_bit3()
{
	a &= ~BIT3;
}

int main()
{
	a = 3;
	V;
	
	printf("a = %d\n", 0x1 << 3);
	
	set_bit3();
	printf("a = %d\n", a);
	
	clear_bit3();
	printf("a = %d\n", a);

	printf("a = %d\n", ver[0]);
	printf("a = %d\n", vver[0]);
	
	return 0;
}


#if 0
/*
 * intel
 */


/*
 * arm v8
 */
void set_bit3(void)
{
	a |= BIT3;
  400590:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400594:	9100f000 	add	x0, x0, #0x3c ; static a
  400598:	b9400000 	ldr	w0, [x0]     ; w0 = [a]
  40059c:	321d0001 	orr	w1, w0, #0x8 ; w1 = a | 0x8
  4005a0:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005a4:	9100f000 	add	x0, x0, #0x3c ; static a
  4005a8:	b9000001 	str	w1, [x0]      ; save static a
}
  4005ac:	d503201f 	nop
  4005b0:	d65f03c0 	ret

00000000004005b4 <clear_bit3>:

void clear_bit3()
{
	a &= ~BIT3;
  4005b4:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005b8:	9100f000 	add	x0, x0, #0x3c ; static a
  4005bc:	b9400000 	ldr	w0, [x0]      ; w0 = [a]
  4005c0:	121c7801 	and	w1, w0, #0xfffffff7 ; w1 = a & 0xfffffff7
  4005c4:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005c8:	9100f000 	add	x0, x0, #0x3c ; static a
  4005cc:	b9000001 	str	w1, [x0]      ; save static a
}
  4005d0:	d503201f 	nop
  4005d4:	d65f03c0 	ret

00000000004005d8 <main>:

int main()
{
  4005d8:	a9be7bfd 	stp	x29, x30, [sp, #-32]!
  4005dc:	910003fd 	mov	x29, sp
	a = 3;
  4005e0:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  4005e4:	9100f000 	add	x0, x0, #0x3c ; static a
  4005e8:	52800061 	mov	w1, #0x3                   	// #3
  4005ec:	b9000001 	str	w1, [x0]                    ; a = 3
	V;
  4005f0:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  4005f4:	911cc001 	add	x1, x0, #0x730 ; x1 = ver
  4005f8:	910063a0 	add	x0, x29, #0x18 ; x0 = x29+0x18
  4005fc:	b9400022 	ldr	w2, [x1]       ; w2 = ver[]
  400600:	b9000002 	str	w2, [x0]       ; w2 ---> [x0]
  400604:	b8402021 	ldur	w1, [x1, #2] ; w1 <--- x1+2
  400608:	b8002001 	stur	w1, [x0, #2] ; w1 ---> x0+2
	
	printf("a = %d\n", 0x1 << 3);
  40060c:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  400610:	911ca000 	add	x0, x0, #0x728 ; parameter
  400614:	52800101 	mov	w1, #0x8                   	// #8
  400618:	97ffff86 	bl	400430 <printf@plt>
	
	set_bit3();
  40061c:	97ffffdd 	bl	400590 <set_bit3>
	printf("a = %d\n", a);
  400620:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400624:	9100f000 	add	x0, x0, #0x3c ; static a
  400628:	b9400001 	ldr	w1, [x0]      ; w1 = [a]
  40062c:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  400630:	911ca000 	add	x0, x0, #0x728 ; parameter
  400634:	97ffff7f 	bl	400430 <printf@plt>
	
	clear_bit3();
  400638:	97ffffdf 	bl	4005b4 <clear_bit3>
	printf("a = %d\n", a);
  40063c:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  400640:	9100f000 	add	x0, x0, #0x3c ; static a
  400644:	b9400001 	ldr	w1, [x0]      ; w1 = [a]
  400648:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  40064c:	911ca000 	add	x0, x0, #0x728 ; parameter
  400650:	97ffff78 	bl	400430 <printf@plt>

	printf("a = %d\n", ver[0]);
  400654:	394063a0 	ldrb	w0, [x29, #24] ; w0 = ver[0]
  400658:	2a0003e1 	mov	w1, w0             ; w1 = ver[0]
  40065c:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  400660:	911ca000 	add	x0, x0, #0x728 ; parameter
  400664:	97ffff73 	bl	400430 <printf@plt>
	printf("a = %d\n", vver[0]);
  400668:	b0000080 	adrp	x0, 411000 <__libc_start_main@GLIBC_2.17>
  40066c:	9100c000 	add	x0, x0, #0x30 ; x0 = vver
  400670:	39400000 	ldrb	w0, [x0]  ; w0 = vver[0]
  400674:	2a0003e1 	mov	w1, w0        ; w1 = vver[0]
  400678:	90000000 	adrp	x0, 400000 <_init-0x3c8>
  40067c:	911ca000 	add	x0, x0, #0x728 ; parameter
  400680:	97ffff6c 	bl	400430 <printf@plt>
	
	return 0;
  400684:	52800000 	mov	w0, #0x0                   	// #0
}

/*
 * arm v7
 */
void set_bit3(void)
{
   104c0:	e52db004 	push	{fp}		; (str fp, [sp, #-4]!)
   104c4:	e28db000 	add	fp, sp, #0
	a |= BIT3;
   104c8:	e59f3018 	ldr	r3, [pc, #24]	; 104e8 <set_bit3+0x28> static a
   104cc:	e5933000 	ldr	r3, [r3]        ; r3 = get a value
   104d0:	e3833008 	orr	r3, r3, #8      ; r3 = r3 | 1000(b)
   104d4:	e59f200c 	ldr	r2, [pc, #12]	; 104e8 <set_bit3+0x28> load static a
   104d8:	e5823000 	str	r3, [r2]        ; save static a
}
   104dc:	e24bd000 	sub	sp, fp, #0
   104e0:	e49db004 	pop	{fp}		; (ldr fp, [sp], #4)
   104e4:	e12fff1e 	bx	lr
   104e8:	00020700 	.word	0x00020700 ; static a

000104ec <clear_bit3>:

void clear_bit3()
{
   104ec:	e52db004 	push	{fp}		; (str fp, [sp, #-4]!)
   104f0:	e28db000 	add	fp, sp, #0
	a &= ~BIT3;
   104f4:	e59f3018 	ldr	r3, [pc, #24]	; 10514 <clear_bit3+0x28>   static a
   104f8:	e5933000 	ldr	r3, [r3]        ; r3 = [a]
   104fc:	e3c33008 	bic	r3, r3, #8      ; a & ~BIT3
   10500:	e59f200c 	ldr	r2, [pc, #12]	; 10514 <clear_bit3+0x28>   static
   10504:	e5823000 	str	r3, [r2]        ; save static
}
   10508:	e24bd000 	sub	sp, fp, #0
   1050c:	e49db004 	pop	{fp}		; (ldr fp, [sp], #4)
   10510:	e12fff1e 	bx	lr
   10514:	00020700 	.word	0x00020700 ; static a

00010518 <main>:

int main()
{
   10518:	e92d4800 	push	{fp, lr}
   1051c:	e28db004 	add	fp, sp, #4
   10520:	e24dd008 	sub	sp, sp, #8
	a = 3;
   10524:	e59f308c 	ldr	r3, [pc, #140]	; 105b8 <main+0xa0> static a
   10528:	e3a02003 	mov	r2, #3          ; r2 = 3
   1052c:	e5832000 	str	r2, [r3]        ; a = 3
	V;
   10530:	e59f2084 	ldr	r2, [pc, #132]	; 105bc <main+0xa4> ver parameter
   10534:	e24b300c 	sub	r3, fp, #12     ; r3 = fp - 12
   10538:	e1a01002 	mov	r1, r2          ; r1 = ver parameter
   1053c:	e3a02006 	mov	r2, #6          ; r2 = 6
   10540:	e1a00003 	mov	r0, r3          ; r0 = fp - 12
   10544:	ebffff7d 	bl	10340 <memcpy@plt>
	
	printf("a = %d\n", 0x1 << 3);
   10548:	e3a01008 	mov	r1, #8         ; r1 = 8
   1054c:	e59f006c 	ldr	r0, [pc, #108]	; 105c0 <main+0xa8> parameter
   10550:	ebffff77 	bl	10334 <printf@plt>
	
	set_bit3();
   10554:	ebffffd9 	bl	104c0 <set_bit3>
	printf("a = %d\n", a);
   10558:	e59f3058 	ldr	r3, [pc, #88]	; 105b8 <main+0xa0> static a
   1055c:	e5933000 	ldr	r3, [r3]        ; r3 = [a]
   10560:	e1a01003 	mov	r1, r3          ; r1 = [a]
   10564:	e59f0054 	ldr	r0, [pc, #84]	; 105c0 <main+0xa8> parameter
   10568:	ebffff71 	bl	10334 <printf@plt>
	
	clear_bit3();
   1056c:	ebffffde 	bl	104ec <clear_bit3>
	printf("a = %d\n", a);
   10570:	e59f3040 	ldr	r3, [pc, #64]	; 105b8 <main+0xa0> static a
   10574:	e5933000 	ldr	r3, [r3]        ; r3 = [a]
   10578:	e1a01003 	mov	r1, r3          ; r1 = [a]
   1057c:	e59f003c 	ldr	r0, [pc, #60]	; 105c0 <main+0xa8>
   10580:	ebffff6b 	bl	10334 <printf@plt>

	printf("a = %d\n", ver[0]);
   10584:	e55b300c 	ldrb	r3, [fp, #-12] ; ver
   10588:	e1a01003 	mov	r1, r3             ; r1 = ver
   1058c:	e59f002c 	ldr	r0, [pc, #44]	; 105c0 <main+0xa8>
   10590:	ebffff67 	bl	10334 <printf@plt>
	printf("a = %d\n", vver[0]);
   10594:	e59f3028 	ldr	r3, [pc, #40]	; 105c4 <main+0xac> vver
   10598:	e5d33000 	ldrb	r3, [r3]    ; r3 = vver[0]
   1059c:	e1a01003 	mov	r1, r3          ; r1 = vver[0]
   105a0:	e59f0018 	ldr	r0, [pc, #24]	; 105c0 <main+0xa8>
   105a4:	ebffff62 	bl	10334 <printf@plt>
	
	return 0;
   105a8:	e3a03000 	mov	r3, #0
}

#endif

